const { Sequelize, DataTypes } = require("sequelize");

const sequelize = new Sequelize("seque", "root", "123456", {
  host: "localhost",
  dialect: "mysql" /* 选择 'mysql' | 'mariadb' | 'postgres' | 'mssql' 其一 */,
});

const User = sequelize.define(
  "User",
  {
    // 在这里定义模型属性
    firstName: {
      type: DataTypes.STRING,
      //   allowNull: false
    },
    lastName: {
      type: DataTypes.STRING,
      // allowNull 默认为 true
      default: "老王",
    },
  },
  {
    // 这是其他模型参数
  }
);

;(async function () {
  try {
    await sequelize.authenticate();

    await User.sync({ alter: true }); 
    console.log("Connection has been established successfully.");

    const jane = await User.create({ firstName: "Jane", lastName: "Willson" });
  
    console.log(jane.toJSON());
} catch (error) {
    console.error("Unable to connect to the database:", error);
  }
})();
